/**
 * StringFormatter
 *
 * @author Chris Pratt
 *
 * 4/1/2012
 */
package com.anodyzed.onyx.text;

public class StringFormatter extends TextFormatter {
  private CharSequence format;

  /**
   * Constructor
   *
   * @param parent The parent TextFormat
   * @param key The Argument Index of Map Key for this node
   * @param bean The Additional Bean Reference String
   * @param format The String Format request
   */
  public StringFormatter (TextFormat parent,CharSequence key,CharSequence bean,CharSequence format) {
    super(parent,key,bean);
    this.format = format;
  } //StringFormatter

  /**
   * Constructor
   *
   * @param parent The parent TextFormat
   * @param key The Argument Index of Map Key for this node
   * @param bean The Additional Bean Reference String
   */
  public StringFormatter (TextFormat parent, CharSequence key, CharSequence bean) {
    super(parent,key,bean);
    this.format = "string";
  } //StringFormatter

  /**
   * Return a modified string value
   *
   * @param args The Formatting Arguments
   * @return The Formatted String
   */
  @Override
  public String toString (Object... args) {
    Object o = getValue(args);
    if(o != null) {
      String s = o.toString();
      if(format.equals("lower")) {
        return s.toLowerCase();
      } else if(format.equals("upper")) {
        return s.toUpperCase();
      } else if(format.equals("trim")) {
        return s.trim();
      }
      return s;
    }
    return null;
  } //toString

} //*StringFormatter
